package com.gilight.base.controller.uiapp;

import com.gilight.base.admin.user.AdminUserService;
import com.gilight.base.aspect.annotation.Auth;
import com.gilight.base.base.ResultEntity;
import com.gilight.base.base.exception.ServiceException;
import com.gilight.base.model.uni.UserDO;
import com.gilight.base.service.impl.UserBizService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author liken
 * 商品管理控制类
 */
@RestController
@RequestMapping("/web/app-user")
public class AppUserController {

    @Autowired
    private AdminUserService adminUserService;

    @Autowired
    private UserBizService userBizService;

    @Auth
    @ApiOperation(value = "更新")
    @RequestMapping(value = "/edit")
    public ResultEntity edit(
            @RequestBody  UserDO user) {
        ResultEntity resultEntity = new ResultEntity();
        try {
            Long adminId = null;
            resultEntity.setData(adminUserService.edit(adminId,user));
        } catch (ServiceException e) {
            e.printStackTrace();
        }
        return resultEntity;
    }

    @ApiOperation(value = "判断当前进入小程序的用户是否是新用户")
    @RequestMapping(value = "/is-new-user")
    public ResultEntity isNewUser(
            String openId) {
            ResultEntity resultEntity = new ResultEntity();
            Boolean isNew = userBizService.getUserByOpenId(openId);
            resultEntity.setData(isNew);
            return resultEntity;
    }
}
